package org.easyexcel.Dao;//package org.easyexcel.Server;
//
//
//import org.easyexcel.Pojo.MyEntity;
////import org.easyexcel.Server.Interface.UserRepository;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//import java.util.List;
//
///**
// * @author DPF
// */
//@Service
//public class MyService {
//    @Autowired
//    private UserRepository userRepository;
//    public MyEntity createUser(MyEntity user) {
//        return userRepository.save(user);
//    }
//
//    public List<MyEntity> getAllUsers() {
//        return userRepository.findAll();
//    }
//
//    public MyEntity getUserById(Long id) {
//        return userRepository.findById(id).orElse(null);
//    }
//
//    public MyEntity updateUser(MyEntity user) {
//        return userRepository.save(user);
//    }
//
//    public void deleteUser(Long id) {
//        userRepository.deleteById(id);
//    }
//}


import org.easyexcel.Pojo.MyEntity;
import org.easyexcel.Pojo.MyReadEntry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author DPF
 */
@Service
public class JdbcBatchDao {
    @Autowired
    private final JdbcTemplate jdbcTemplate;
    public JdbcBatchDao(){
        this.jdbcTemplate = null;
    }

    @Autowired
    public JdbcBatchDao(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }


    public List<Map<String, Object>> getUsers() {
        String sql = "SELECT * FROM user";
        return jdbcTemplate.queryForList(sql);
    }

    public void batchInsertUsers(List<MyEntity> users) {
        String sql = "INSERT INTO user (name, age,email) VALUES (?,?,?)";
        List<Object[]> batchArgs = users.stream()
                .map(user -> new Object[]{user.getName(), user.getAge(), user.getEmail()}).collect(Collectors.toList());
        jdbcTemplate.batchUpdate(sql, batchArgs);
    }

    public List<MyReadEntry> getAllUsers() {
        String sql = "SELECT * FROM user";
        return jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(MyReadEntry.class));
    }
    public Integer findActResultLogByCondations(int count) {
        return 100;
    }

}
